package com.example.logintokenredis.controller;

import com.example.logintokenredis.entity.Auth;
import com.example.logintokenredis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {//仅用来测试登录后通过token获取信息
    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    UserMapper userMapper;

    @RequestMapping("/getinfo")
    public Auth getInfo(HttpServletRequest request, @CookieValue("token")String token){
        System.out.println(token);
        String temp= (String) redisTemplate.opsForValue().get("token:"+token);
        int uid=Integer.parseInt(temp);
        Auth auth=userMapper.getByUid(uid);
        return auth;
    }
}
